package com.genius.config;

import com.genius.Interceptor.HeaderInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    // 需要排除的地址
    public static final String[] excludeUrls = {"/passport/login", "/passport/getCheckImage",
            "/passport/register","/passport/getEmailCheckCode",
            "/index/sayWelcome", "/*/api-docs"};
    @Bean
    public HeaderInterceptor getHeaderInterceptor() {
        return new HeaderInterceptor();
    }

    /**
     * 注册拦截器，并且拦截指定的路由，否则不生效
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(getHeaderInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns(excludeUrls);
    }
}
